<template>
	<view class="equipment">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				常见问题
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="center">
				<view class="sousuo">
					<input type="text" placeholder="请输入关键字" v-model="keywords" @confirm="sousuo"/>
					<image :src="baseUrl + '/wximage/sousuo.png'" @click="sousuo"></image>
				</view>
			</view>
		</view>
		<view class="mendian">
			<view class="shuju" v-for="(item,index) in list" :key="index">
				<view :class="[attrIndex==item.id?'top shujuts clearfix':'top clearfix']" @click="attrIndex = item.id">
					<image :src="baseUrl + '/wximage/wttubiao1.png'" class="tubiao fl" v-if="index == 0"></image>
					<image :src="baseUrl + '/wximage/wttubiao2.png'" class="tubiao fl" v-if="index == 1"></image>
					<image :src="baseUrl + '/wximage/wttubiao3.png'" class="tubiao fl" v-if="index == 2"></image>
					<image :src="baseUrl + '/wximage/wttubiao4.png'" class="tubiao fl" v-if="index == 3"></image>
					<view class="title fl">{{item.title}}</view>
					<image :src="baseUrl + '/wximage/xia.png'" class="you fr" v-if="attrIndex == item.id"></image>
					<image :src="baseUrl + '/wximage/right.png'" class="you fr" v-else></image>
				</view>
				<view class="miaoshu" v-for="(item1,index1) in item.articleList" :key="index1" v-if="attrIndex == item.id">
					<view class="bottom clearfix" @click="topage('/subpackageA/user/second/article?id=' + item1.id)">
						<view class="title fl">{{item1.title}}</view>
						<image :src="baseUrl + '/wximage/right.png'" class="fr"></image>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				keywords: '',
				list: [],
				attrIndex: 18,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
			
			this.request({
				url: '/xcx/articlehelp',
				data: {
					attrIndex: this.attrIndex,
					keywords: '',
				}
			}).then(res => {
				if (res.data.code == 200) {
					this.list = res.data.data;
				} else {
					uni.showToast({
						title: '请求失败，请稍后再试',
						icon: 'none'
					})
				}
			})
		},
		methods: {
			sousuo() {
				let keywords = this.keywords;
				let attrIndex = this.attrIndex;
				
				this.request({
					url: '/xcx/articlehelp',
					data: {
						attrIndex: attrIndex,
						keywords: keywords,
					}
				}).then(res => {
					if (res.data.code == 200) {
						this.list = res.data.data;
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			topage(url){
				uni.navigateTo({
					url
				})
			},
			fanhui() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.equipment {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 10rpx 40rpx 0;
			box-sizing: border-box;
		
			.center{
				
				.sousuo {
					width: 100%;
					box-sizing: border-box;
					position: relative;
						
					input {
						width: 100%;
						height: 60rpx;
						line-height: 60rpx;
						background: #ffffff;
						border-radius: 30rpx;
						padding-left: 30rpx;
						color: #999999;
						box-sizing: border-box;
					}
						
					image {
						width: 72rpx;
						height: 40rpx;
						position: absolute;
						right: 10rpx;
						top: 10rpx;
						z-index: 10;
					}
					
					.iconfont {
						font-size: 40rpx;
						position: absolute;
						right: 24rpx;
						top: 10rpx;
						color: #5C88FA;
					}
				}
			}
		}
		
		.mendian{
			width: 90%;
			margin: 0 auto;
			z-index: 70;
			margin-top: -200rpx;
			
			.shuju{
				width: 100%;
				padding: 20rpx 40rpx 20rpx 24rpx;
				box-sizing: border-box;
				background: #FFFFFF;
				border-radius: 20rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;
				margin-bottom: 20rpx;
				
				.top{
					height: 60rpx;
					line-height: 60rpx;
					
					.tubiao{
						width: 60rpx;
						height: 60rpx;
					}
					
					.title{
						font-size: 28rpx;
						color: #333333;
						font-weight: 700;
						margin-left: 14rpx;
					}
					
					.you{
						width: 40rpx;
						height: 40rpx;
						margin-top: 6rpx;
					}
				}
				
				.miaoshu{
					width: 100%;
					padding: 0 20rpx;
					box-sizing: border-box;
					
					.bottom{
						height: 80rpx;
						line-height: 80rpx;
						border-bottom: 1rpx solid #F1F1F1;
						
						image{
							width: 30rpx;
							height: 30rpx;
							margin-top: 22rpx;
						}
						
						.title{
							font-size: 24rpx;
							color: #666666;
							margin-left: 14rpx;
						}
					}
				}
				
				.bottom:last-child{
					border: none;
				}
			}
			
			.shujuts{
				border-bottom: 1rpx solid #F1F1F1;
				padding-bottom: 78rpx;
			}
		}
		
		.empty{
			width: 100%;
			margin: 20rpx auto 0;
			text-align: center;
			padding-bottom: 20rpx;
			
			image{
				width: 390rpx;
				height: 340rpx;
			}
			
			text{
				display: block;
				margin-top: 30rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>